

import requests
import time, datetime
import random


url = 'https://www.shipmentlink.com/servlet/TUF1_CaptchaUtils?d=1610004449796'
headers = {
    # 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
    # 'Referer':'https://www.shipmentlink.com/tuf1/jsp/TUF1_QuickSearch.jsp',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
    'Host': 'www.moguproxy.com'

}
response = requests.get(url=url,headers=headers)


def get_img(dt):
    # 目标网址
    # url = 'https://www.shipmentlink.com/servlet/TUF1_CaptchaUtils?d=' + str(dt)
    # 蘑菇街
    url = 'http://www.moguproxy.com/proxy/validateCode/createCode?time=' + str(dt)
    res = requests.get(url=url,headers=headers).content
    with open('./moguimg/'+str(dt)+'.jpg','wb') as f:
        f.write(res)
        print('下载完成 ',)

if __name__ == '__main__':
    print('hellow request')
    while True:
        try:
            now = int(round(time.time() * 1000))
            time.sleep(random.randint(1, 3))
            get_img(dt=now)
        except Exception as e:
            now = int(round(time.time() * 1000))
            get_img(dt=now)

